/* BaseNode.cpp */

#include <stdio.h>

#include "safeproxy.h"
#include "BaseNode.h"

//-----------------------------------------------------------------------------
// Constructor
BaseNode::BaseNode() {
	_socket = 0;
}

//-----------------------------------------------------------------------------
// Deconstructor.
BaseNode::~BaseNode() {
	
	// If the socket was connected, then we need to clean it up.
	ASSERT(_socket >= 0);
	if (_socket > 0) {
		close(_socket);
	}
	
	// If the event structure was established, might need to make sure the event 
	// has been deleted, and clean up the structure.
}


void EventRun(int fd, short event, void *arg)
{
	BaseNode *node = (BaseNode *) arg;
	
	ASSERT(fd > 0);
	ASSERT(event != 0);
	ASSERT(arg != NULL);
	
	
	printf("Event. fd=%d, event=%d\n", fd, event);

	node->OnEvent(fd, event);
}


void BaseNode::OnEvent(int fd, short event) 
{
	ASSERT(fd == _socket);
	
	event_add(&_event, NULL);
	
	printf("OnEvent. fd=%d, event=%d\n", fd, event);
	
}

